<style lang="scss" scoped>
	.content {
		width: 100%;
		background-color: white;

		padding: 30rpx 25rpx;
	}

	.list {

		border-bottom: 1px solid #ccc;
		align-items: flex-start;
		padding: 25rpx 0;

		.red {
			transform: translateY(6rpx);
		}

		.textarea {
			width: 550rpx;
			height: 120rpx;
			font-size: 28rpx;
		}

		.mic {
			height: 120rpx;
			width: 80rpx;
			border-left: 1px solid #ccc;
			padding-left: 20rpx;
		}

		.ipt,
		.picker {
			width: 550rpx;
			text-align: right;
		}

		.uploadfile {
			width: 550rpx;

			.btns {
				width: 100%;
				justify-content: flex-end;

				.btn {
					padding: 0 30rpx;
					height: 64rpx;
					opacity: 1;
					background: #fffefe;
					border: 2rpx solid #409eff;
					border-radius: 34rpx;
				}
			}
		}

		.record {
			width: 550rpx;
		}
	}

	.line2 {
		width: 100%;
		border-bottom: 1px solid #ccc;
		line-height: 80rpx;

		.line {
			width: 100%;

			.t2 {
				width: 60%;
			}
		}
	}

	.footer {
		height: 160rpx;

		background-color: white;

	}
</style>

<template>
	<view class="content">
		<view class="f34 bold" style="padding:0 30rpx;border-bottom: 1px solid #ccc;padding-bottom: 20rpx;">操作处理</view>
		<view class="list between-flex f28">
			<view class="align-flex  gray">
				<span class="red">*</span>处理状态
			</view>
			<view class="picker textColor ">
				处理
			</view>
		</view>
		<view class="list between-flex f28">
			<view class="align-flex p-left10 gray">
				处理说明
			</view>
			<textarea class="textarea" v-model="explan" placeholder="请填写" />
		</view>
		<view class="list between-flex f28">
			<view class="align-flex  gray">
				<span class="red">*</span>处理进度（单位：%）
			</view>
			<input class="ipt" style="width:300rpx;" :disabled="role!=1" type="number" v-model="compRate" placeholder="负责人可填写" />
		</view>

		<view class="list between-flex f28">
			<view class="align-flex  gray">
				<span class="red">*</span>处理时间
			</view>
			<view class="picker blue ">
				{{processTime? processTime:'请选择'}}
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>


		<view class="list between-flex f28">
			<view class="align-flex">
				附件
			</view>
			<view class="uploadfile">
				<view class="btns align-flex m-bottom20">
					<view class="btn center-flex blue " @click="chooseImg" style="margin-right: 30rpx;">拍照</view>
					<view class="btn center-flex  blue" @click="uploadfile">上传附件</view>
				</view>
				<view class="p-top10 between-flex" v-for="item,index in enclosure" :key="index">
					<view class="align-flex blue" @click="$open(item.url)">
						<u-icon name="file-text" color="#409EFF" size="38"></u-icon>
						{{item.fileName.substring(item.fileName.length-10)}}
					</view>
					<u-icon @click="delfile(index)" name="close" color="#666666" size="30"></u-icon>
				</view>
			</view>
		</view>
		<view class="footer center-flex">
			<view class="lbtn" @click="submit">
				提交
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		props: {
			role:{
				default: 2
			},
			taskId: {
				default: 0
			},
			info:{
				default: {}
			}
		},
		data() {
			return {
				head: this.$head,
				explan: '',
				compRate: '',
				processTime: '',
				enclosure: [],

			}
		},
		created() {
			this.getdate()
			if(this.info.compRate){
				this.compRate=this.info.compRate
			}
		},

		methods: {

			submit() {
				if (!this.compRate&&this.role==1) {
					this.$msg('请输入处理进度！')
					return
				}
				if(this.role==1&&this.compRate!=parseInt(this.compRate)||this.compRate>100){
					this.$msg('请输入小于等于100的整数')
					return
				}
				var obj = {
					taskId: this.taskId,
					explan: this.explan,
					compRate: this.compRate?this.compRate:'0',
					processTime: this.processTime+':00'
				}

				var enclosure = []
				this.enclosure.forEach(item => {
					enclosure.push({
						name: item.oldName,
						url: item.url
					})
				})
				obj['attachment'] = JSON.stringify(enclosure)
				// console.log(obj)
				this.$showloading()
				this.$pop.ajaxPost('/bus/taskInfo/deal', obj).then((res) => {
					uni.hideLoading()
					if (res.code == 0) {
						this.$msg('操作成功')
						this.$emit('submit')
					} else {
						this.$msg(res.msg)
					}
				})

			},
			getdate() {
				var date = new Date();
				var seperator1 = "-";
				var seperator2 = ":";
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				var hour = date.getHours()
				var min = date.getMinutes()
				month < 10 ? month = '0' + month : ''
				strDate < 10 ? strDate = '0' + strDate : ''
				hour < 10 ? hour = '0' + hour : ''
				min < 10 ? min = '0' + min : ''
				var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + ' ' + hour +
					seperator2 + min

				this.processTime = currentdate;
			},
			delfile(index) {
				this.enclosure.splice(index, 1)
			},
			//选择图片
			async chooseImg() {

				var file = await this.$chooseImg()

				this.enclosure.push(file)

			},
			async uploadfile() {
				console.log(23232)
				var file = await this.$uploadfile()
				this.enclosure.push(file)

			},

		}
	}
</script>
